package com.zahb.qadx.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zahb.qadx.R;
import com.zahb.qadx.model.PendTaskModel;
import com.zahb.qadx.ui.activity.MyCourseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huwei.
 * Data 2020-10-10.
 * Time 10:29.
 * 待完成任务adapter
 */
public class PendingsalesAdapter extends RecyclerView.Adapter<PendingsalesAdapter.PendingsalesViewHodler> {
    private Context mContext;
    private List<PendTaskModel> pendTaskModelList = new ArrayList<>();

    public PendingsalesAdapter(Context mContext, List<PendTaskModel> pendTaskModelList) {
        this.mContext = mContext;
        this.pendTaskModelList = pendTaskModelList;
    }
    public void setGridDataList(List<PendTaskModel> pendTaskModelList) {
       this.pendTaskModelList = pendTaskModelList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public PendingsalesViewHodler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PendingsalesViewHodler(LayoutInflater.from(mContext).inflate(R.layout.item_pendingsales_task, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull PendingsalesViewHodler holder, int position) {
        holder.title.setText(pendTaskModelList.get(position).getTitle());
        holder.assistant_title.setText(pendTaskModelList.get(position).getAssistant_title());
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mContext.startActivity(new Intent(mContext, MyCourseActivity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return pendTaskModelList !=null ? pendTaskModelList.size() : 0;
    }

    static class PendingsalesViewHodler extends RecyclerView.ViewHolder {
        private ImageView img;
        private TextView title, assistant_title;

        public PendingsalesViewHodler(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            title = itemView.findViewById(R.id.tv_title);
            assistant_title = itemView.findViewById(R.id.tv_assistant_title);
        }
    }
}
